{include file="public_head" /}

<!-- Select2 -->
<link href="__STATIC__/css/select/select2.min.css" rel="stylesheet">
<!-- upload -->
<link href="__STATIC__/css/uploads.css" rel="stylesheet">
<!-- upload_arr -->
<link href="__STATIC__/plupload/plupload.css" rel="stylesheet">
<body class="nav-md">

<div class="container body">

    <div class="main_container">

        {include file="public_sidebar,public_nav" /}
        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">

                <div class="page-title">
                    <div class="title_left">
                        <h3>优惠券管理</h3>
                    </div>
                </div>
                <div class="clearfix"></div>
                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">
                            <div class="x_title">
                                <h2>{$mate_title}
                                </h2>
                                <ul class="nav navbar-right panel_toolbox">
                                    <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                    </li>
                                    <li><a class="close-link"><i class="fa fa-close"></i></a>
                                    </li>
                                </ul>
                                <div class="clearfix"></div>
                            </div>
                            <div class="x_content">
                                <br/>

                                <form class="form-horizontal form-label-left" enctype="multipart/form-data" action=""
                                      method="post" id="registerForm" >
                                    {if condition="input('system') neq 1"}
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">接收会员：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <select name="shop_assignor_id[]" class="select2_multiple form-control"
                                                    multiple="multiple"
                                                    style="width: 500px;" tabindex="-1"
                                                    datatype="*"
                                                    nullmsg="请选择接收会员！" errormsg="请选择接收会员！"
                                            >
                                                <option value="0"
                                                >
                                                    请选择指派人
                                                </option>
                                                {volist name="$member" id="list"}
                                                <option
                                                        {in name='list.id' value='$item.shop_assignor_id|default=""'}selected{/in}
                                                value="{$list.id}"
                                                >
                                                {$list.username}
                                                </option>
                                                {/volist}

                                            </select>
                                        </div>
                                    </div>
                                    {/if}
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">优惠券类型：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <select name="type" class="select2_single form-control"   onchange="single()"

                                                    style="width: 500px;" tabindex="-1"
                                                    datatype="*"
                                                    nullmsg="请选择指派人！" errormsg="请选择指派人！"
                                            >
                                                <option value="1" {eq name="$item.type|default=''" value="1"}selected{/eq}>商品</option>

                                                <option value="2" {eq name="$item.type|default=''" value="2"}selected{/eq}>服务</option>
                                            <option value="3" {eq name="$item.type|default=''" value="3"}selected{/eq}>通用</option>
                                                <option value="4" {eq name="$item.type|default=''" value="4"}selected{/eq}>礼包</option>
                                            {neq name=":input('id')" value="65"}{/neq}
                                            </select>
                                        </div>
                                    </div>



                                    <div class="form-group" id="single" {in name="$item.type|default='1'" value="1,3,4"}style="display: none;"{/in}>
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" >服务分类:</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <select name="single_id"  class="select2_single" {eq name=":request()->action()" value="update"}readonly{/eq}
                                                    style="width: 500px;" tabindex="-1"
                                                   <!--datatype="*" -->
                                                    nullmsg="请选择栏目分类！" errormsg="请选择栏目分类！"
                                            >

                                                {volist name="single_list" id="items"}
                                                <option value="{$items.id}"
                                                    {eq name="$items.level" value="1"}{/eq}
                                                    {eq name="$items.id" value="$item.single_id|default=''"}selected{/eq}
                                                >
                                                {neq name="$items.level" value="1"}{:str_repeat('&nbsp&nbsp',$items.level)}{/neq}|{:str_repeat('--',$items.level)}{$items.cat_name}
                                                </option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>

                            <div class="form-group" id="gift2" {in name="$item.type|default='1'" value="1,2,3"}style="display: none;"{/in}>
                            <label class="control-label col-md-3 col-sm-3 col-xs-12" >礼包列表:</label>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <select name="single_id2[]"  class="select2_multiple form-control"  multiple="multiple" {eq name=":request()->action()" value="update"}readonly{/eq}
                                style="width: 500px;" tabindex="-1"

                                nullmsg="请选择礼包！" errormsg="请选择礼包！"
                                >
                                <option value="0">全部礼包</option>
                                {volist name="$gift" id="items"}

                                <option value="{$items.id}"
                                        {in name='items.id' value='$item.single_id|default=""'}selected{/in}>
                                ID:{$items.id}-{$items.title}
                                </option>
                                {/volist}
                                </select>
                            </div>
                        </div>
                            {if condition="input('system') eq 1"}
                            <div class="form-group">
                                <label class="control-label col-md-3 col-sm-3 col-xs-12">优惠券角色：</label>
                                <div class="col-md-6 col-sm-6 col-xs-12">
                                    <select name="role_id" class="select2_single form-control"   onchange="single()"

                                            style="width: 500px;" tabindex="-1"
                                            datatype="*"
                                            nullmsg="请选择指派人！" errormsg="请选择指派人！"
                                    >
                                        <!--<option value="1" {eq name="$item.role_id|default=''" value="1"}selected{/eq}>邀请会员</option>-->

                                        {if condition="input('system') eq 1 && input('card_type') eq 2"}
                                        <option value="5" selected>会员卡</option>
                                        {else/}
                                        <option value="2" {eq name="$item.role_id|default=''" value="2"}selected{/eq}>被邀请会员</option>
                                        <option value="3" {eq name="$item.role_id|default=''" value="3"}selected{/eq}>注册会员</option>
                                        <option value="4" {eq name="$item.role_id|default=''" value="4"}selected{/eq}>认证会员</option>
                                        {/if}
                                    </select>
                                </div>
                            </div>
                            {/if}

                                    <div class="divider-dashed"></div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">优惠券标题：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请输入优惠券标题"
                                                   class="form-control col-md-7 col-xs-12" name="title"
                                                   value="{$item.title|default=''}"
                                                   datatype="*"
                                                   nullmsg="请输入优惠券标题！" errormsg="请输入优惠券标题！"
                                            >
                                        </div>
                                    </div>

                                    <div class="divider-dashed"></div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">优惠券描述：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <textarea type="text" placeholder="请填写优惠券描述"
                                                      datatype="*"
                                                      nullmsg="请填写优惠券描述！" errormsg="请填写优惠券描述！"
                                                      class="form-control col-md-7 col-xs-12" name="content" style="max-width:100%">{$item.content|default=''}</textarea>
                                        </div>
                                    </div>

                                    <div class="divider-dashed"></div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">优惠券金额：</label>
                                        <div class="col-md-2 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请输入使用价格"
                                                   class="form-control col-md-7 col-xs-12" name="actual_price"
                                                   value="{$item.actual_price|default=''}"
                                                   datatype="*"
                                                   nullmsg="请输入优惠券金额！" errormsg="请输入优惠券金额！"
                                            >
                                        </div>
                                        <label class="control-label col-md-1 col-sm-1 col-xs-1">消费满：</label>
                                        <div class="col-md-2 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请输入满减价格"
                                                   class="form-control col-md-7 col-xs-12" name="virtual_price"
                                                   value="{$item.virtual_price|default=''}"
                                                   datatype="*"
                                                   nullmsg="请输入满减金额！" errormsg="请输入满减金额！"
                                            >
                                        </div>
                                        <label class="control-label col-md-0.5 col-sm-0.5 col-xs-0.5">可用</label>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">使用区间时间：</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请选择时间区间"
                                                   class="form-control col-md-7 col-xs-12" name="interval_timer"
                                                   id="interval_timer"
                                                   {present name="$item.id"}
                                                   value="{$item.start_time|date='Y-m-d',###} / {$item.end_time|date='Y-m-d',###}"
                                                   {/present}
                                                   datatype="*"
                                                   nullmsg="请选择时间区间！" errormsg="请选择时间区间2！"
                                            >
                                        </div>
                                    </div>
                            {if condition="input('system') neq 1"}
                                    <div class="form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12">发放数量：</label>
                                        <div class="col-md-2 col-sm-6 col-xs-12">
                                            <input type="text" placeholder="请填写发放数量"
                                                      datatype="*"
                                                      nullmsg="请填写发放数量！" errormsg="请填写发放数量！"
                                                      class="form-control col-md-7 col-xs-12" name="number" value="{$item.number|default=''}" style="max-width:100%" />
                                        </div>
                                    </div>
                            {/if}
                        {if condition="input('system') eq 1 && input('card_type',2)"}
                        <div class="form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12">会员卡数量：</label>
                            <div class="col-md-2 col-sm-6 col-xs-12">
                                <input type="text" placeholder="请填写发放数量"
                                       datatype="*"
                                       nullmsg="请填写发放数量！" errormsg="请填写发放数量！"
                                       class="form-control col-md-7 col-xs-12" name="zcs" value="{$item.zcs|default=''}" style="max-width:100%" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3 col-sm-3 col-xs-12">激活时间(天)：</label>
                            <div class="col-md-1 col-sm-6 col-xs-12">
                                <input type="text" placeholder="激活时间"
                                       class="form-control col-md-7 col-xs-12" name="jihuo_day"
                                       value="{$item.jihuo_day|default=''}"
                                >
                            </div>
                        </div>
                        {/if}
                                    <!--<div class="form-group">-->
                                        <!--<label class="control-label col-md-3 col-sm-3 col-xs-12">上传组图：【720*365】</label>-->
                                        <!--<div class="col-md-6 col-sm-6 col-xs-12">-->

                                            <!--<div class="uploader white">-->
                                                <!--<input type="button"  id="logo_upload_btn" class="button" value="批量上传" {if condition="request()->action() eq 'update'"} {/if}/>-->
                                            <!--</div>-->

                                            <!--<div id="logo_upload_area" style='width:80%'>-->
                                                <!--<div id='photos_area' class="photos_area clearfix">-->

                                                    <!--{if condition="($Request.action eq 'update') && ($item.multi_pic neq 'N;') && ($item.multi_pic neq '')"}-->
                                                    <!--{foreach :unserialize($item['multi_pic']) as $picValue}-->
                                                    <!--<div class="item">-->
                                                        <!--<input type="hidden" name="picArr[]" value="{$picValue}">-->
                                                        <!--<img src="__PUBLIC__/{$picValue}" width="100px" height="100px">-->
                                                        <!--<div class="operate">-->
                                                            <!--<i class="toleft">左移</i>-->
                                                            <!--<i class="toright">右移</i>-->
                                                            <!--<i class="del">删除</i>-->
                                                        <!--</div>-->
                                                    <!--</div>-->
                                                    <!--{/foreach}-->
                                                    <!--{/if}-->

                                                <!--</div>-->
                                                <!--<div class="alert alert-success" role="alert"-->
                                                     <!--style="margin:10px 0;"><strong><span-->
                                                        <!--class="glyphicon glyphicon-flag"></span>点击批量上传按钮上传多张图片:</strong>&nbsp;&nbsp;单张图片大小不超过500KB,格式为jpg,png,gif,jpeg-->
                                                <!--</div>-->

                                            <!--</div>-->

                                        <!--</div>-->
                                    <!--</div>-->

                                    {include file="auding_status" /}
                                    <div class="form-group">
                                        <div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
                                            {present name="$item.id"}
                                            <input type="hidden" name="id" value="{$item.id}">
                                            {/present}
                                            <!--<input type="hidden" name="member_id" value="0"/>-->
                                            <button type="submit" class="btn btn-primary">提交</button>
                                            <a type="reset" class="btn btn-success" onclick="history.go(-1)">返回</a>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <!-- /page content -->

        </div>

    </div>
</div>

{include file="public_foot" /}
<!-- upload_arr -->
<script src="__STATIC__/js/upload.photos.js"></script>
<script type="text/javascript" src="__STATIC__/plupload/plupload.full.min.js"></script>
<!-- validform -->
<script src="__STATIC__/js/Validform_v5.3.2_min.js"></script>
<script src="__STATIC__/js/layer.js"></script>
<!-- daterangepicker -->
<script src="__STATIC__/js/datepicker/daterangepicker.js"></script>
<!--select-->
<script src="__STATIC__/js/select/select2.full.min.js"></script>

<script>
    $('#interval_timer').daterangepicker(null,
        function(start, end, label) {
            console.log(start.toISOString(), end.toISOString(), label);
        });

    // 组图排序 删除图片
    $(".toleft").live("click", function () {
        var item = $(this).parent().parent(".item");
        var item_left = item.prev(".item");
        if ($("#photos_area").children(".item").length >= 2) {
            if (item_left.length == 0) {
                item.insertAfter($("#photos_area").children(".item:last"));
            } else {
                item.insertBefore(item_left);
            }
        }

    })

    $(".toright").live("click", function () {
        var item = $(this).parent().parent(".item");
        var item_right = item.next(".item");
        if ($("#photos_area").children(".item").length >= 2) {
            if (item_right.length == 0) {
                item.insertBefore($("#photos_area").children(".item:first"));
            } else {
                item.insertAfter(item_right);
            }
        }
    })

    $(".del").live("click", function () {
        $(this).parent().parent(".item").remove();
    })
    // validform
    $(function () {
        $(".select2_single").select2({
            placeholder: "请选择分类",
            allowClear: true
        });
        $.Tipmsg.r = null;

        var showmsg = function (msg) {
            //假定你的店铺商品提示方法为showmsg， 在方法里可以接收参数msg，当然也可以接收到o及cssctl;
            alert(msg);
        }
        $("#registerForm").Validform({
            tiptype: function (msg) {
                layer.msg(msg);
            },
            tipSweep: true
        });


        // upload
        new uploadPreview({UpBtn: "up_img", DivShow: "imgdiv", ImgShow: "imgShow"});

        // select2



        $(":radio").click(function () {

            if (this.checked) {
                if ($(this).attr("id") == "freight_type_1") {
                    $("#immobilization").show();
                    $("#template").hide();
                }else{
                    $("#immobilization").hide();
                    $("#template").hide();
                }
            }
        });
    });

    // 组图上传
    var uploader = new plupload.Uploader({
        runtimes: 'html5,flash,silverlight,html4',
        browse_button: 'logo_upload_btn',
        url: "/index.php/client/shop_goods/uploadarr.html",
        flash_swf_url: '__STATIC__/plupload/Moxie.swf',
        silverlight_xap_url: '__STATIC__/plupload/Moxie.xap',
        filters: {
            max_file_size: '500kb',
            mime_types: [
                {title: "files", extensions: "jpg,png,gif,jpeg"}
            ]
        },
        multi_selection: true,
        init: {
            FilesAdded: function (up, files) {
                $("#btn_submit").attr("disabled", "disabled").addClass("disabled").val("正在上传...");
                var item = '';
                plupload.each(files, function (file) { //遍历文件
                    item += "<div class='item' id='" + file['id'] + "'><div class='progress'><span class='bar'></span><span class='percent'>0%</span></div></div>";
                });
//                alert(item.length);
//                if(item.length >= 2){
//                    alert('最多只能上传2张图片');
//                    return false;
//                }
                $("#photos_area").append(item);
                uploader.start();
            },
            UploadProgress: function (up, file) { //上传中，显示进度条
                var percent = file.percent;
                $("#" + file.id).find('.bar').css({"width": percent + "%"});
                $("#" + file.id).find(".percent").text(percent + "%");
            },
            FileUploaded: function (up, file, info) {

                var data = eval("(" + info.response + ")");

                $("#" + file.id).html("<input type='hidden' name='picArr[]' value='" + data.src + "'><img src='__PUBLIC__/" + data.src + "' alt='" + data.name + "' width='100px' height='100px'><div class='operate'><i class='toleft'>左移</i><i class='toright'>右移</i><i class='del'>删除</i></div>")
                $("#btn_submit").removeAttr("disabled").removeClass("disabled").val("提 交");
                if (data.error != 0) {
                    layer.msg(data.error);
                }
            },
            Error: function (up, err) {
                layer.msg(err.message);
                $("#btn_submit").removeAttr("disabled").removeClass("disabled").val("提 交");
            }
        }
    });
    uploader.init();

    function ef(){
       var num = $("#num").val();

       if(num <= 1){

           layer.msg("派发数量必须大于1");
           return false;
       }

    }
    $(".select2_single").select2({
        placeholder: "请选择分类",
        allowClear: true
    });
    // select2
    $(".select2_multiple").select2({
        maximumSelectionLength: 0,
        placeholder: "请选择接收会员",
        allowClear: true
    });
    // validform
    $(function () {

        $.Tipmsg.r = null;
        $.Datatype.int = /^[1-9]\d*$/;
        var showmsg = function (msg) {
            //假定你的店铺商品提示方法为showmsg， 在方法里可以接收参数msg，当然也可以接收到o及cssctl;
            alert(msg);
        }
        $("#registerForm").Validform({
            tiptype: function (msg) {
                layer.msg(msg);
            },
            tipSweep: true,

        });

        // interval_timer
        $('#interval_timer').daterangepicker(null,
                function(start, end, label) {
                    console.log(start.toISOString(), end.toISOString(), label);
                });


        $(".select2_multiple").select2({
            maximumSelectionLength: 0,
            placeholder: "请选择接收会员",
            allowClear: true
        });


    })
    function single() {
        var type = $('[name="type"]').val();

        $('#gift2').hide();
        $('#single').hide();
        if(type == 2){
            $('#single').show();
        }
        if(type == 4){

            $('#gift2').show();
        }
    }
</script>
</body>

</html>
